<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-static-top">
  <div class="container">
    <!-- Branding Image -->
    <a class="navbar-brand " href="{{ url('/') }}">
      Laravel Shop
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <!-- Left Side Of Navbar -->
      <ul class="navbar-nav mr-auto">
        <!-- 顶部类目菜单开始 -->
        <!-- 判断模板是否有 $categoryTree 变量 -->
        @if(isset($categoryTree))
          <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
               aria-expanded="false" id="categoryTree">所有类目 <b class="caret"></b></a>
            <ul class="dropdown-menu" aria-labelledby="categoryTree">
              <!-- 遍历 $categoryTree 集合，将集合中的每一项以 $category 变量注入 layouts._category_item 模板中并渲染 -->
              @each('layouts._category_item', $categoryTree, 'category')
            </ul>
          </li>
      @endif
      <!-- 顶部类目菜单结束 -->
        <li class="nav-item {{ active_class(if_route('topics.index')) }}">
          <a class="nav-link" href="{{ route('topics.index') }}">话题</a>
        </li>
        <li class="nav-item {{ category_nav_active(1) }}">
          <a class="nav-link" href="{{ route('topic_categories.show', 1) }}">分享</a>
        </li>
        <li class="nav-item {{ category_nav_active(2) }}">
          <a class="nav-link" href="{{ route('topic_categories.show', 2) }}">教程</a>
        </li>
        <li class="nav-item {{ category_nav_active(3) }}">
          <a class="nav-link" href="{{ route('topic_categories.show', 3) }}">问答</a>
        </li>
        <li class="nav-item {{ category_nav_active(4) }}">
          <a class="nav-link" href="{{ route('topic_categories.show', 4) }}">公告</a>
        </li>
      </ul>

      <!-- Right Side Of Navbar -->
      <ul class="navbar-nav navbar-right">
        <!-- 登录注册链接开始 -->
        @guest
          <li class="nav-item"><a class="nav-link" href="{{ route('login') }}">登录</a></li>
          <li class="nav-item"><a class="nav-link" href="{{ route('register') }}">注册</a></li>
        @else
          <li class="nav-item">
            <a class="nav-link mt-1" href="{{ route('cart.index') }}"><i class="fa fa-shopping-cart"></i></a>
          </li>
          {{--          <li class="nav-item">--}}
          {{--            <a class="nav-link mt-1 mr-3 font-weight-bold" href="{{ route('topics.create') }}">--}}
          {{--              <i class="fa fa-plus"></i>--}}
          {{--            </a>--}}
          {{--          </li>--}}
          <li class="nav-item notification-badge">
            <a
              class="nav-link mr-3 badge badge-pill badge-{{ Auth::user()->notification_count > 0 ? 'hint' : 'secondary' }} text-white"
              href="{{ route('notifications.index') }}">
              {{ Auth::user()->notification_count }}
            </a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
               aria-haspopup="true" aria-expanded="false">
              <img src="{{ Auth::user()->avatar }}" class="img-responsive img-circle" width="30px" height="30px">
              {{ Auth::user()->name }}
            </a>
            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
              @can('manage_contents')
                <a class="dropdown-item" href="{{ url(config('administrator.uri')) }}">
                  <i class="fas fa-tachometer-alt mr-2"></i>
                  管理后台
                </a>
                <div class="dropdown-divider"></div>
              @endcan
              <a class="dropdown-item" href="{{ route('users.show', Auth::id()) }}">
                <i class="far fa-user mr-2"></i>个人中心
              </a>
              <a class="dropdown-item" href="{{ route('users.edit', Auth::id()) }}">
                <i class="far fa-edit mr-2"></i>编辑资料
              </a>
              <a class="dropdown-item" href="{{ route('products.favorites') }}">
                <i class="far fa-heart mr-2"></i>我的收藏
              </a>
              <a class="dropdown-item" href="{{ route('user_addresses.index') }}">
                <i class="fa fa-telegram mr-2"></i>收货地址
              </a>
              <a class="dropdown-item" href="{{ route('orders.index') }}">
                <i class="fa fa-shopping-basket mr-2"></i>我的订单
              </a>
              <a class="dropdown-item" href="{{ route('installments.index') }}">
                <i class="fa fa-credit-card-alt mr-2"></i>分期付款
              </a>
              <div class="dropdown-divider"></div>
              <a class="dropdown-item" id="logout" href="#"
                 onclick="event.preventDefault();document.getElementById('logout-form').submit();">退出登录</a>
              <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                {{ csrf_field() }}
              </form>
            </div>
          </li>
      @endguest
      <!-- 登录注册链接结束 -->
      </ul>
    </div>
  </div>
</nav>
<!-- 判断模板是否有 $categoryTree 变量 -->
{{--@if(isset($categoryTree))--}}
{{--  @include('layouts._category', $categoryTree, 'category')--}}
{{--@endif--}}
